package special;

import node.TreeNode;

import java.util.ArrayList;
import java.util.List;

class BSTIterator {
    List<Integer> list = new ArrayList<>();
    int cursor = 0;
    private void init(List<Integer> list, TreeNode node){
        if (node == null)
            return;
        init(list, node.left);
        list.add(node.val);
        init(list, node.right);
    }

    public BSTIterator(TreeNode root) {
        init(list, root);
    }
    
    public int next() {
        return list.get(cursor++);
    }
    
    public boolean hasNext() {
        return cursor < list.size();
    }
}